//
//  AnnounceRequireController.m
//  SSB
//
//  Created by Lyn on 16/9/21.
//  Copyright © 2016年 TNT. All rights reserved.
//

#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenScale (ScreenWidth / 375.f)

#import "AnnounceRequireController.h"
#import "RequireAcctionView.h"
#import "RequireDataModel.h"
#import "RequireActionButton.h"

#import "MTChatViewController.h"
#import "UIViewController+JTNavigationExtension.h"


#import "UIView+PFAddtion.h"
#import "NSObject+CCNSDictionary.h"
#import "UIColor+GDBAddtion.h"
@interface AnnounceRequireController ()

@property (nonatomic, weak) UIScrollView *scrollView;

@property (nonatomic, strong) NSArray *requireDataArray;

@property (nonatomic, strong) NSMutableArray *rowStatus;

@end

@implementation AnnounceRequireController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initNavigation];
    self.view.backgroundColor = [UIColor redColor];
    self.jt_fullScreenPopGestureEnabled = YES;
    [self setup];
 

    // Do any additional setup after loading the view.
}

- (void)setup {
    self.navigationController.navigationBar.translucent = NO;
    self.title = @"发布有求";
    
    self.rowStatus = [NSMutableArray arrayWithArray:@[@1,@0,@0,@0,@0,@0]];
    self.tableView.backgroundColor = themeGrayColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //获取发布有求页面数据
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"RequireData.plist" ofType:nil];
    self.requireDataArray = [NSArray arrayWithContentsOfFile:filePath];
}

#pragma mark ---tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.requireDataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   UITableViewCell * cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"requireCell"];
    cell.backgroundColor = themeGrayColor;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //建立模型
    RequireDataModel *model = [NSObject ccObjectFromClass:[RequireDataModel class] dict:self.requireDataArray[indexPath.row]];
    //布局
    RequireAcctionView *actionView = [RequireAcctionView viewWithTitle:model.ItemTitle titleImage:[UIImage imageNamed:model.ItemImageName] itemArray:model.ItemContainArray itemActionArray:model.ItemActionStr status:[self.rowStatus[indexPath.row] boolValue]];
//    actionView.frame = CGRectMake(0.f, 0, ScreenWidth, 179.f * ScreenScale);
    //设置左侧色条
    [actionView setLeftColor:[UIColor pf_colorWithHexString:model.ItemLeftColor]];
    actionView.delegate = self;
    actionView.detailBtn.rowNum = indexPath.row;
    cell.height  = actionView.height + 4.f;
    [cell addSubview:actionView];
    return cell;
}

-(void)changeCellHeight:(BOOL)selectedStatus indexNum:(NSInteger)indexNum {
    self.rowStatus[indexNum]= @(!selectedStatus);
        [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexNum inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
//    [self.tableView reloadData];
}
#pragma mark --前往详情页
- (void)goToDetailView:(NSString *)titile sortNum:(NSInteger)sortNum rowNum:(NSInteger)rowNum actionType:(NSString *)actionType {
    
//    RequireDetailController *requireDetailCon = [[RequireDetailController alloc]init];
//    RequireDataModel *model = [NSObject ccObjectFromClass:[RequireDataModel class] dict:self.requireDataArray[rowNum]];
//    requireDetailCon.titleImageName = model.ItemIconArray[sortNum];
//    requireDetailCon.titleStr = titile;
//    requireDetailCon.actionType = actionType;
//    [self.navigationController pushViewController:requireDetailCon animated:YES];
}



//导航栏内容设置
-(void)initNavigation {
    
    self.navigationItem.title = @"发布有求";
    
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"back"] highImage:[UIImage imageNamed:@"back anxia"] target:self action:@selector(backClick)];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(0x45c75a)]  forBarMetrics:UIBarMetricsDefault];
    NSMutableDictionary *attr = [NSMutableDictionary dictionary];
    attr[NSFontAttributeName] = [UIFont boldSystemFontOfSize:17];
    attr[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:attr];
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"news"] highImage:[UIImage imageNamed:@"news_gray"] target:self action:@selector(chatClick)];
}
#pragma mark ------点击跳转界面
-(void)chatClick {
    MTChatViewController *vc = [MTChatViewController shareChatViewController];
    [self.navigationController pushViewController:vc animated:YES];
    NSLog(@"third%@",vc);
    
}

-(void)backClick {
    [self dismissViewControllerAnimated:YES completion:nil];
}


@end
